<template>
  <atom-table
    :ref="ref"
    :data="data"
    v-bind="attrs"
    :navigation="navigation"
    @loadPage="loadPage"
    @handleEdit="handleEdit"
    @handleDelete="handleDelete"
    @handleDetail="handleDetail"
    @handleClick="handleClick"
    @handleDbClick="handleDbClick"
    @handleCreate="handleCreate"
    @handleDeleteMultiple="handleDeleteMultiple"
    @handleSearch="handleSearch"
    @handleReset="handleReset"
    @handleSelect="handleSelect"
  ></atom-table>
</template>

<script>
const ref = "mainTable";
export default {
  name: ref,
  components: {},
  inject: ["anc"],
  data() {
    return {
      ref,
      loading: false,
      navigation: {
        show: true,
        opts: [10, 30, 50, 100],
        page: { total: 0, pageSize: 10, pageNumber: 1 },
      },
    };
  },
  props: {
    data: {
      default: () => {
        return [];
      },
    },
  },
  watch: {},
  computed: {
    attrs() {
      return {
        query: {
          show: true,
          labelWidth: 100, //label宽度
          labelPosition: "right", //label位置
          cols: 4, //一行几列
          onlyRead: false, //是否只读
          collapse: true,
          columns: [
           
            {
              title: "产品名称", //字段标题
              key: "productName", //字段key
              line: false, //是否独占一行
              titleStyle: {},
              default: {
                value: "",
                empty: false,
                logic: "&&",
                operator: ">",
              },
              tip: {
                icon: "",
                size: 16,
                iconStyle: {},
                theme: "light",
                placement: "top",
                content: "",
                contentStyle: {},
              },
              config: {
                //编辑器配置，可以是函数，参数为(item,index,data)
                editor: {
                  //编辑器配置
                  type: "text", //编辑器类型
                  // options: this.anc.technologyParamsOptions,
                },
                style: {
                  //样式配置
                },
              },
              // rules: [
              //   {
              //     required: false,
              //     type: "string",
              //     message: "必填",
              //     trigger: ["change", "blur"],
              //   },
              // ],
            },
            {
              title: "参数名称", //字段标题
              key: "paramName", //字段key
              line: false, //是否独占一行
              titleStyle: {},
              default: {
                value: "",
                empty: false,
                logic: "&&",
                operator: ">",
              },
              tip: {
                icon: "",
                size: 16,
                iconStyle: {},
                theme: "light",
                placement: "top",
                content: "",
                contentStyle: {},
              },
              config: {
                //编辑器配置，可以是函数，参数为(item,index,data)
                editor: {
                  //编辑器配置
                  type: "text", //编辑器类型
                  // options: this.anc.productOptions,
                },
                style: {
                  //样式配置
                },
              },
              // rules: [
              //   {
              //     required: false,
              //     type: "string",
              //     message: "必填",
              //     trigger: ["change", "blur"],
              //   },
              // ],
            },
           
          ], //字段列表
          rules: {},
        },
        queryData: {}, //数据
        table: {
          config: {
            autoHeight: true,
            stripe: true, //条纹
            size: "default", //尺寸
            loading: false, //是否加载
            rowClassName: "", //行样式
            tableHeight: "auto", //表高
            style: {},
            checkColumn: true,
            numberColumn: true,
            action: false,
            additionalAction: true,
            sort: {
              asc: [],
              desc: [],
            },
            actionFn: (row, column, index, item) => {
              return true;
            },
            additionalActionFn: (row, column, index, item) => {
              // if(row.name==='panhao'){
              //   item['disabled'] = true;
              // }else{
              //   item['disabled'] = false;
              // }
              return true;
            },
          },
          columns: [
          
            {
              title: "产品名称", //字段标题
              key: "productName", //字段key
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              title: "参数名称", //字段标题
              key: "paramName", //字段key
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              title: "参数单位", //字段标题
              key: "unit", //字段key
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              title: "最大值", //字段标题
              key: "maxParam", //字段key
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              title: "最小值", //字段标题
              key: "minParam", //字段key
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              title: "实际值",
              key: "actual",
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              title: "时间",
              key: "collectionTime",
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            // {
            //   title: "是否超限",
            //   key: "isOverLimit",
            //   width: "auto",
            //   align: "center",
            //   show: true,
            //   sort: "asc",
            // },
            {
              title: "是否上报",
              key: "isReport",
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              key: "createTime",
              title: "创建时间",
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              key: "createdBy",
              title: "创建人",
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              key: "updateTime",
              title: "修改时间",
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
            {
              key: "updatedBy",
              title: "修改人",
              width: "auto",
              align: "center",
              show: true,
              sort: "asc",
            },
          ],
          additionalAction: {
            key: "additionalAction",
            title: "操作",
            slot: "additionalAction",
            width: 200,
            fixed: "right",
            align: "center",
            buttons: [
              {
                title: "编辑", //按钮标题
                style: {}, //按钮样式
                event: (row, column, index, item) => {
                  this.anc.handleEdit(row,  index)
                }, //按钮事件
              },
            ],
          },
        },
        // navigation: {
        //   show: true,
        //   opts: [10, 30, 50, 100],
        //   page: { total: 0, pageSize: 10, pageNumber: 1 },
        // },
        tools: {
          addButton: false,
          batchDeleteButton: false,
          searchIcon: false,
          downloadIcon: false,
          uploadIcon: false,
          uploadUrl: "/",
          tableSizeIcon: false,
          fullscreenIcon: false,
          refreshIcon: false,
          columnSettingIcon: false,
          columnSortIcon: false,
          buttons: [
            {
              title: "上报数据",
              event: (btn) => {
                this.anc.uploadData()
              },
              type:"primary"
            },
            {
              title: "同步刷新",
              event: (btn) => {
               this.anc.asyncData()
              },
              style: {
                marginLeft: "40px !important"
              },
              type:"success"
            },
            {
              title: "添加批次",
              event: (btn) => {
               this.anc.handleCreate()
              },
              style: {
                marginLeft: "40px !important"
              },
              type:"success"
            },
          ],
        },
      };
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);

      this.loadPage(this.navigation.page, {});
    });
  },
  methods: {
    loadPage(pageNavigation, filter, orderBy = {}) {
      //   //删除查询项中属性值为空的查询条件
      this.anc.loadPage(pageNavigation, filter, orderBy);
    },
    handleEdit(row, index) {
      console.log(row, index);
      this.anc.handleEdit(row, index);
    },
    handleDelete(row, index) {
      this.anc.handleDelete(row, index);
    },
    handleDetail(row, index) {
      this.anc.handleDetail(row);
    },
    handleSelect(selection) {
      this.anc.dataSet.selection = selection;
    },
    handleClick(row, index) {},
    handleDbClick(row, index) {},
    handleDeleteMultiple(selection) {},
    handleSearch(filter) {
      this.navigation.pageNumber = 1;
      this.loadPage(this.navigation.page, filter);
    },
    handleReset(data, completeData, defaultData) {
      this.navigation.pageNumber = 1;
      this.queryData = {};
      this.loadPage(this.navigation.page, {});
    },
    handleCreate() {
      this.anc.handleCreate();
    },
  },
};
</script>
<style scoped></style>
